#include <config.hpp>
SSHConfig* SSHConfig::config = new SSHConfig();

SSHConfig::SSHConfig(){
     ifstream fs;
    fs.open("../config/sproxy.conf",ios::in);
    char buff[1024] = {0};
    string s;
    while(!fs.eof()){
        fs.getline(buff,1024);
        string buf(buff);
        int index = buf.find('=');
        if(index > 0){
            configMap[buf.substr(0,index)] = buf.substr(index+1, buf.size());
        }
    }
}

SSHConfig::SSHConfig(string file){
    ifstream fs;
    fs.open(file,ios::in);
    char buff[1024] = {0};
    string s;
    while(!fs.eof()){
        fs.getline(buff,1024);
        string buf(buff);
        int index = buf.find('=');
        if(index > 0){
            configMap[buf.substr(0,index)] = buf.substr(index+1, buf.size());
        }
    }
}

SSHConfig* SSHConfig::getConfig(){
    return config;
}

void SSHConfig::reload(string file) {
    SSHConfig* old = config;
    config = new SSHConfig(file);
    delete(old);
}